<template>
  <header class='header'>
    <section class='navs'>
      <nav class='logo fl'>
        <img src='../../assets/logo.jpg' />
      </nav>
      <nav class='text fl ml10'>
        <span>夕阳的博客</span>
      </nav>
      <nav class='nav-menus fl'>
        <ul class='menus'>
          <li class='menu' v-for='menu in menus' :key='menu.name' @click='select($event, menu)'>
            <a href='javascript:;'>{{ menu.title }}</a>
            <ul class='menu-subs'>
              <li class='menu-sub' v-for='sub in menu.children' :key='sub.name' @click='select($event, sub)'>
                <a href='javascript:;'>{{ sub.title }}</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <nav class='nav-menus-small'>
        <a href='javascript:;' @click='toggleShow'>
          <i class='icon iconfont icon-menus menus-small-icon'></i>
        </a>
        <ul class='menus-small' v-show='menusSamllShow'>
          <li class='menus-small-sub' v-for='menu in menus' :key='menu.name' @click='select($event, menu)'>
            <a href='javascript:;'>{{ menu.title }}</a>
          </li>
        </ul>
      </nav>
    </section>
  </header>
</template>
<script>
import smenus from "@/config/header-data.js";
import { defineComponent, ref, reactive } from "vue";
import { useRouter } from "vue-router";
import { screenChange } from "@/utils/resize";
export default defineComponent({
  name: "sheader",
  setup (props) {
    const router = useRouter();

    let amenus = Object.assign([], smenus)
    if (screenChange() != 'wid-850')    {
      let children = amenus[1].children;
      amenus.splice(1, 1, children[0], children[1])
    }
    const menus = reactive(amenus);

    const select = (evt, menu) => {
      evt.stopPropagation();
      if (menu.children && menu.children.length > 0) return;

      router.push({ name: menu.name });
      menusSamllShow.value = false;
    };

    const menusSamllShow = ref(false);
    const toggleShow = (e) => {
      menusSamllShow.value = !menusSamllShow.value;
    }


    return {
      menus,
      select,
      menusSamllShow,
      toggleShow
    };
  },
});
</script>
<style lang="scss" scoped>
.header {
  width: 100%;
  // height: 60px;
  background: #1c2327;
  position: absolute;
  top: 0;
  z-index: 100;
}
.navs {
  width: 900px;
  margin: auto;

  .text {
    color: #fff;
    font-family: cursive;
    font-size: 20px;
    height: 60px;
    line-height: 60px;
    margin-right: 45px;
  }
  .logo {
    // padding: 5px 0;
    padding-top: 10px;
    img {
      border-radius: 60%;
      width: 40px;
      height: 40px;
    }
  }

  .nav-menus > .menus {
    height: 60px;
    line-height: 60px;
  }
  .menu {
    display: inline-block;
    color: #fff;
    padding: 0 25px;
    transition: all 0.2s ease-in;
    cursor: pointer;
    position: relative;
  }
  li.menu:hover {
    background-color: #737f99;
  }
  // .menu > .menu-sub-area {
  //   display: none;
  // }
  li.menu:hover > .menu-subs {
    z-index: 100;
    opacity: 1;
    visibility: visible;
    margin: 0;
  }
  .menu-subs {
    margin: 20px 0 0 0;
    opacity: 0;
    visibility: hidden;
    position: absolute;
    top: 60px;
    left: 0;
    z-index: 1;
    background: #3e3e3e;
    -webkit-transition: all 0.2s ease-in-out;
    -moz-transition: all 0.2s ease-in-out;
    -ms-transition: all 0.2s ease-in-out;
    -o-transition: all 0.2s ease-in-out;
    transition: all 0.2s ease-in-out;
    height: initial;
    line-height: initial;
  }
  .menu-subs > li.menu-sub {
    color: #fff;
    transition: all 0.2s ease-in;
    cursor: pointer;
    padding: 20px 25px;
    display: inline-block;
  }
  ul.menu-subs > li:first-child > a:after {
    content: "";
    position: absolute;
    left: 30px;
    top: -6px;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #3e3e3e;
  }
}
.nav-menus-small {
  display: none;
  right: 5px;
  position: absolute;
  height: 60px;
  line-height: 60px;
  text-align: right;

  .menus-small-icon {
    font-size: 35px;
    color: white;
    margin-right: 10px;
  }
  .menus-small {
    position: relative;
    margin-top: -10px;
    background-color: #1c2327;
    color: white;
    padding: 5px 10px;
    text-align: center;
  }
  .menus-small-sub {
    height: 25px;
    line-height: 25px;
    padding: 5px;
  }
}
</style>
